package jp.co.redfox.archclub.poker.hand;

import java.util.EnumSet;

import jp.co.redfox.archclub.poker.Hand;


public class HandEvaluator {
    public static boolean winnerIsMyHand(Hand myHand, Hand rivalHand) {
        EnumSet<KindOfHand> ranks = EnumSet.allOf(KindOfHand.class);
        int myHandRank = 0;
        int otherHandRank = 0;
        int rankCounter = 0;
        KindOfHand compareHand = KindOfHand.HiCard;
        for (KindOfHand hand : ranks) {
            rankCounter++;
            if (hand.matches(myHand)) myHandRank = rankCounter;
            if (hand.matches(rivalHand)) otherHandRank = rankCounter;
            compareHand = hand;
        }
        if (myHandRank > otherHandRank)
            return true;
        else if (otherHandRank > myHandRank)
            return false;
        else
            return compareHand.compare(myHand, rivalHand) > 0;
    }
}
